import std.stdio;
import core.thread;
import std.functional;

shared static this()
{}

shared static ~this()
{}

void doFiber()
{
    writeln("fiber start in  : ", Thread.getThis.id());
    Fiber.yield();
    writeln("fiber start Call one  : ", Thread.getThis.id());
    Thread.sleep(dur!("seconds")(5));
    Fiber.yield();
    writeln("fiber start Call Two  : ", Thread.getThis.id());
    Fiber.yield();
    writeln("fiber Call end  : ", Thread.getThis.id());
}

void main()
{
    Fiber fb = new Fiber(toDelegate(&doFiber));
    writeln(fb.state);
    fb.call();
    Thread th = new Thread((){writeln(fb.state, "   in thread"); fb.call();Thread.sleep(dur!("seconds")( 20 ));});
    th.start();
    writeln(fb.state);
    Thread.sleep(dur!("seconds")( 2 ));
    writeln(fb.state);
    //Thread.sleep(dur!("seconds")( 5 ));
    th = new Thread((){writeln(fb.state, "   in thread");fb.call();});
    th.start();
    Thread.sleep(dur!("seconds")( 2 ));
    writeln(fb.state);
    fb.call();
    writeln(fb.state);
}
